<?php

namespace pos\modules\mall\controllers;

use pos\extensions\ApiBaseController;
use pos\services\mall\MallHoldService;

class MallHoldController extends ApiBaseController
{

    // 挂单
    public function actionHold()
    {
        $params = \Yii::$app->request->post();
        $rules = [
            [['type', 'cart'], 'required', 'message' => '{attribute}属必填项'],
            [['phone', 'coupon_code'], 'default', 'value' => 0, 'message' => '参数错误'],
        ];
        $validate = $this->validateParams($params, $rules);
        if ($validate) {
            return $this->jsonError($validate);
        }
        return MallHoldService::hold($this->params);
    }

    // 挂单
    public function actionHoldList()
    {
        $params = \Yii::$app->request->post();
        $rules = [
        ];
        $validate = $this->validateParams($params, $rules);
        if ($validate) {
            return $this->jsonError($validate);
        }
        return MallHoldService::holdList($this->params);
    }

    // 挂单取回
    public function actionHoldBack()
    {
        $params = \Yii::$app->request->post();
        $rules = [
            [['id'], 'required', 'message' => '{attribute}属必填项'],
        ];
        $validate = $this->validateParams($params, $rules);
        if ($validate) {
            return $this->jsonError($validate);
        }
        return MallHoldService::holdBack($this->params);
    }

    // 支付
    public function actionHoldPay()
    {
        $params = \Yii::$app->request->post();
        $rules = [
            [['id'], 'required', 'message' => '{attribute}属必填项'],
        ];
        $validate = $this->validateParams($params, $rules);
        if ($validate) {
            return $this->jsonError($validate);
        }
        return MallHoldService::holdPay($this->params);
    }


}
